﻿#ifndef PST_NEARFIELDDATAGENERATOR_H
#define PST_NEARFIELDDATAGENERATOR_H

#include <QObject>
#include <vtkSmartPointer.h>

class vtkTable;
class vtkDataSet;
class vtkStructuredGrid;

namespace pst
{
    class NearFieldDataGenerator : public QObject
    {
        Q_OBJECT

    public:
        NearFieldDataGenerator(QObject* parent = nullptr);
        ~NearFieldDataGenerator();

    public:

        void setInputData(vtkTable* table);

        void setLogTheData(bool useLog);
        bool getLogTheData();

        void setNormalizeTheData(bool useNormalize);
        bool getNormalizeTheData();

        void setTableExtends(int xMax, int yMax, int zmax);
        //设置了使用计算的extend，则不使用传入的extend
        void setUseComputedExtend(bool use);
        bool getUseComputedExtend();

        //重建时是否逆序构造需要做
        void inverserXYZ(bool inverse);

        bool update();

        vtkDataSet* getOutputData(); // get the vtkDataSiz

        void SetLogFactory(double factory);


    private:
        /// @brief 将表格转为StructuredGrid(表面重建)
        /// @param inputTable 输入的4列直角坐标表格
        /// @param outStructuredGrid 表面重建后的数据
        void transformTableToStructuredGrid(vtkTable* inputTable,
            vtkStructuredGrid* outStructuredGrid, int xMax, int yMax, int zMax, bool reverseXYZ = false);

        /// @brief 对表格取对数
        /// @param inputTable 输入表格(多行多列的球坐标表格)
        /// @param outputTable 输出表格(多行多列的球坐标取对数后的表格，只对r取对数)
        void logTheTable(vtkTable* inputTable, vtkTable* outputTable, double& logedMinimalValue);

        void normalizeTheTable(vtkTable* inputTable, vtkTable* outputTable);

        void computeTableExtends();
    private:
        bool m_useLog;
        bool m_useNormalize;
        double m_logFactory;
        vtkTable* m_originalTable;
        vtkSmartPointer<vtkTable> m_resultTable;
        vtkSmartPointer<vtkStructuredGrid> m_resultDataSet;
        double m_setTableExtends[3];
        double m_computedTableExtends[3];
        bool m_inverserXYZ;
        bool m_useComputedExtecnd;
    };
}
#endif // NearFieldDataGenerator
